package com.gack.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.gack.business.model.Department;
import com.gack.business.vo.DepartmentItemVO;
import com.gack.business.vo.EnterpriseFrameworkVO;

@Repository
public interface DepartmentRepository extends JpaRepository<Department, String>, JpaSpecificationExecutor<Department>{

	@Query("select d.id"
			+ " from Department d"
			+ " where d.parentId=:departmentId"
			+ " and d.status=1")
	List<String> findNextSubDepartmentIdByDepartmentId(@Param("departmentId")String departmentId);//查询某部门的下一级子部门id(不包含已删除部门)
	
	@Query("select new com.gack.business.vo.EnterpriseFrameworkVO$DepartmentBasicInfo(d.id, d.name, d.no, d.level, d.number, d.parentId)"
			+ " from Department d"
			+ " where d.enterpriseId=:enterpriseId"
			+ " and d.status=1")
	List<EnterpriseFrameworkVO.DepartmentBasicInfo> findDepartmentBasicInfoByEnterpriseId(@Param("enterpriseId") String enterpriseId);//根据公司id查询公司架构类的内部类部门信息对象集合(不包括已删除部门)
	
	@Query("select new com.gack.business.vo.DepartmentItemVO(d.id, d.name, d.number)"
			+ " from Department d"
			+ " where d.enterpriseId=:enterpriseId"
			+ " and d.parentId = '0'"
			+ " and d.status=1")
	List<DepartmentItemVO> findTopDepartmentItemVOByEnterpriseId(@Param("enterpriseId") String enterpriseId);//获取某公司一级部门ItemVO(不包括已删除部门)
	
	@Query("select d.name, d.parentId"
			+ " from Department d"
			+ " where d.id=:departmentId")
	List<Object[]> findNameAndParentIdByDepartmentId(@Param("departmentId") String departmentId);//查询某部门的名称及父部门id
	
}
